using System.Data.OleDb;
using System.Data;
using System;
namespace Studio.Data.Utilities
{

    /// <summary>
    /// By marstone.net, Since 2010/03/16
    /// </summary>
    public class ExcelHelper
    {

        public static DataSet ExcelToDataSet(string Path)
        {
            OleDbConnection conn = null;
            try
            {
                string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
                conn = new OleDbConnection(strConn);
                conn.Open();
                string strExcel = "";
                OleDbDataAdapter myCommand = null;
                DataSet ds = null;
                strExcel = "select * from [sheet1$]";
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                ds = new DataSet();
                myCommand.Fill(ds, "table1");
                return ds;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return null;
            }
            finally
            {
                if (conn != null) conn.Close();
            }
        }
    }
}
